package xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.presenter;

import android.content.Context;
import android.nfc.tech.NfcA;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import xixirupan.tmgp.tencent.com.vmeim.R;
import xixirupan.tmgp.tencent.com.vmeim.config.URLConfig;
import xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.model.categorydetailbean.ProductsBaen;

/**
 * Created by lenovo on 2016/10/25.
 */

public class CatgoryDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<ProductsBaen> lists;
    private Context context;
    private LayoutInflater inflater;
    public CatgoryDetailAdapter(List<ProductsBaen> lists,Context context,LayoutInflater inflater)
    {
        this.lists =lists;
        this.context =context;
        this.inflater =inflater;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
}

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.categoty_detail_item1, parent, false);
        ViewHolder holder =new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder )
        {
            List<String> pictureUrlList = lists.get(position).getPictureUrlList();
            String url = pictureUrlList.get(0);
            String imgulr = URLConfig.UrlMain.SHOPCAR_IMGBEFORE+url;

            Glide.with(context).load(imgulr).into(((ViewHolder) holder).imageView);
            String name = lists.get(position).getName();
            ((ViewHolder) holder).textView_title.setText(name);
            int vmeiPrice = lists.get(position).getVmeiPrice();
            double vprice =vmeiPrice/100;
            int price = lists.get(position).getPrice();
            double _price =price/100;
            ((ViewHolder) holder).textView_vmeiprice.setText("¥"+_price+"");

            ((ViewHolder) holder).textView_orgprice.setText("¥"+vprice+"");
        }

    }

    @Override
    public int getItemCount() {
        return lists.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
             ImageView imageView;
        TextView textView_title;
        TextView textView_vmeiprice;
        TextView textView_orgprice;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView  = (ImageView) itemView.findViewById(R.id.imageView_detail_categoty);
             textView_title  = (TextView) itemView.findViewById(R.id.title_detail_category);
             textView_vmeiprice = (TextView) itemView.findViewById(R.id.category_detail_vmeiprice);
            textView_orgprice = (TextView) itemView.findViewById(R.id.orginalprice_detail_catogry);
        }
    }
}
